package com.xiyue.lenovo.componentattr;

import android.content.ComponentName;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button bn = (Button) findViewById(R.id.bn);
        bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //创建一个ComponentName对象
                ComponentName comp = new ComponentName(MainActivity.this,SecondActivity.class);
                Intent intent = new Intent();
                //为Intent设置component属性
                intent.setComponent(comp);
               /* //根据指定的组件类来创建Intent
                Intent intent = new Intent(ComponentAttr.this,secondActivity.class);*/
                startActivity(intent);
            }
        });
    }
}
